import request from '@/utils/http'

// 权限列表
export const getRightsListAPI = (type)=>{
    return request({
        method:'GET',
        url:`rights/${type}`
    })
}

// 角色列表
export const getRolesListAPI = () =>{
    return request({
        method:'GET',
        url:'roles'
    })
}

// 删除角色指定权限
export const delRolesAuthorityAPI = (roleId,rightId) =>{
    return request({
        method:'DELETE',
        url:`roles/${roleId}/rights/${rightId}`
    })
}

// 添加角色
export const addRolesAPI = (role) => {
    return request({
        method:'POST',
        url:'roles',
        data:role
    })
}

// 修改角色
export const editRolesAPI = (edit) => {
    return request({
        method:'PUT',
        url:`roles/${edit.id}`,
        data:{
            roleName:edit.roleName,
            roleDesc:edit.roleDesc
        }
    })
}

// 删除角色
export const delRolesAPI = (id) =>{
    return request({
        method:'DELETE',
        url:`roles/${id}`
    })
}

// 分配权限
export const grantRolesAPI = (roleId,rids) =>{
    return request({
        method:'POST',
        url:`roles/${roleId}/rights`,
        data:{
            rids
        }
    })
}